/**
 * Copyright 2007-2010 非也
 * All rights reserved. 
 * 
 * This library is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License v3 as published by the Free Software
 * Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, see http://www.gnu.org/licenses/lgpl.html.
 *
 */
package org.fireflow2.designer.eclipse.commands;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.fireflow.pdl.fpdl20.diagram.Fpdl20DiagramElement;
import org.fireflow.pdl.fpdl20.process.SubProcess;
import org.fireflow2.designer.eclipse.modelwrapper.ModelWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.NodeWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.Wrapper;
import org.fireflow2.designer.eclipse.palette.DiagramElementSubType;

/**
 *
 * @author 非也 nychen2000@163.com
 * Fire Workflow 官方网站：www.firesoa.com 或者 www.fireflow.org
 *
 */
public abstract class AbstractCreateNodeCommand extends Command {
//	protected SubProcessWrapper parentWrapper = null;
	protected ModelWrapper parentWrapper = null;
	
	protected Fpdl20DiagramElement diagramElm = null;
	protected DiagramElementSubType subType = null;
	protected NodeWrapper nodeWrapper = null;
	protected Rectangle rect = null;
	
	public Wrapper getNewModelWrapper(){
		return nodeWrapper;
	}
//	public void setSubflowWrapper(
//			SubProcessWrapper parentWrapper) {
//		this.subflowWrapper = parentWrapper;
//	}
	
	public void setParentWrapper(ModelWrapper pWrapper){
		this.parentWrapper = pWrapper;
	}
	
	public void setNewDiagramElement(Fpdl20DiagramElement element) {
		this.diagramElm = element;
	}
	
	public void setDiagramElementSubType(DiagramElementSubType subType){
		this.subType = subType;
	}
	
	public Rectangle getRect() {
		return rect;
	}
	public void setRect(Rectangle rect) {
		this.rect = rect;
	}
	
	protected abstract NodeWrapper createNodeWrapper();
	protected abstract String findANewNodeName(SubProcess subflow,String nodeType);
	
	public void execute(){
		this.nodeWrapper = createNodeWrapper();
		if (nodeWrapper==null)return;
		parentWrapper.addChild(nodeWrapper);

	}
	
	public void redo(){
		if (nodeWrapper==null)return;
		parentWrapper.addChild(nodeWrapper);
	}
	
	public void undo(){
		if (nodeWrapper==null)return;
		parentWrapper.deleteChild(nodeWrapper);
	}
}
